package com.atguigu.project.app

import com.atguigu.project.bean.UserVisitAction
import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
 * Author atguigu
 * Date 2020/10/31 14:27
 */
object ProjectApp {
    def main(args: Array[String]): Unit = {
        // 1. 先读取数据
        val conf: SparkConf = new SparkConf().setAppName("ProjectApp").setMaster("local[2]")
        val sc: SparkContext = new SparkContext(conf)
        val lineRDD: RDD[String] = sc.textFile("c:/user_visit_action.txt")
        val userVisitActionRDD = lineRDD.map(line => {
            val datas: Array[String] = line.split("_")
            UserVisitAction(
                datas(0),
                datas(1).toLong,
                datas(2),
                datas(3).toLong,
                datas(4),
                datas(5),
                datas(6).toLong,
                datas(7).toLong,
                datas(8),
                datas(9),
                datas(10),
                datas(11),
                datas(12).toLong)
        })
        
        
        // 2. 计算需求1：
        // CategoryTopApp.calcTop10Category_1(sc, userVisitActionRDD)
        //        println("------")
        //        CategoryTopApp.calcTop10Category_2(sc, userVisitActionRDD)
        //val top10Category = CategoryTopApp.calcTop10Category_5(sc, userVisitActionRDD)
        // 3. 计算需求2:
        //CategoryTopSesseionApp.statTop10Session_4(sc, userVisitActionRDD, top10Category)
        
        // 4.需求3
        PageConversionApp.calcPageConversionRate(sc, userVisitActionRDD, "1,2,3,4,5,6,7")
        
        sc.stop()
    }
}
